﻿using System;

abstract class Shape
{
    public abstract double Area { get; }
    public abstract bool IsValid { get; }
}
class Rectangle : Shape
{
    public double Length { get; }
    public double Width { get; }

    public override double Area
    {
        get
        {
            return Length * Width;
        }
    }
    public override bool IsValid
    {
        get
        {
            return Length > 0 && Width > 0;
        }
    }
    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }
}
//square is a kind of rectangle
class Square : Rectangle
{
    public Square(double sideLength) : base(sideLength, sideLength)
    {
    }
}

class Triangle : Shape
{
    public double Side1 { get; }
    public double Side2 { get; }
    public double Side3 { get; }

    public override double Area
    {
        get
        {
            double p = (Side1 + Side2 + Side3) / 2;
            return Math.Sqrt(p * (p - Side1) * (p - Side2) * (p - Side3));
        }
    }

    public override bool IsValid
    {
        get
        {
            return ( Side1 > 0 && Side2 > 0 && Side3 > 0 && Side1 + Side2 > Side3 && Side2 + Side3 > Side1 && Side3 + Side1 > Side2 );
        }
    }

    public Triangle(double side1, double side2, double side3)
    {
        Side1 = side1;
        Side2 = side2;
        Side3 = side3;
    }
}

class Program
{
    static void Main()
    {
        Rectangle rect = new Rectangle(6, 9);
        Console.WriteLine($"Area of the Reactangle：{rect.Area}");

        Square square = new Square(5);
        Console.WriteLine($"Area of the Square：{square.Area}");

        Triangle tri = new Triangle(3, 4, 5);
        Console.WriteLine($"Area of the Triangle：{tri.Area}");
    }
}
